package ai.people.netmon.warning.controller;

import ai.people.core.security.support.RequestHolderUtil;
import ai.people.netmon.framework.domain.oss.vo.UploadVO;
import ai.people.netmon.framework.domain.warning.request.WarningInfoExportRequest;
import ai.people.netmon.framework.domain.warning.vo.WarningExportListDataVO;
import ai.people.netmon.framework.model.request.PageKeyWordsRequest;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.netmon.warning.service.WarningExportService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * 导出接口
 *
 * @author yuanqinglong
 * @date 2022/7/27 19:05
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/export")
public class WarningExportController {


    private final WarningExportService warningExportServiceImpl;



    /**
     * 导出记录列表
     *
     * @return {@link Result}<{@link PageResponse}<{@link List}<{@link WarningExportListDataVO}>>>
     */
    @PostMapping("/record/list")
    public Result<PageResponse<List<WarningExportListDataVO>>> listExport(@RequestBody PageKeyWordsRequest pageKeyWordsRequest) {
        PageResponse<WarningExportListDataVO> exportRecords = warningExportServiceImpl.exportRecords(pageKeyWordsRequest, RequestHolderUtil.getUserId());
        return ResultUtil.success(exportRecords);
    }


    /**
     * 导出
     *
     * @param warningInfoExportRequest 警告信息出口要求
     * @return {@link Result}<{@link UploadVO}>
     * @throws IOException ioexception
     */
    @PostMapping("/save")
    public Result<UploadVO> export(@Validated @RequestBody List<WarningInfoExportRequest> warningInfoExportRequest) throws IOException {
        return warningExportServiceImpl.exportWarningInfo(warningInfoExportRequest);
    }

}
